package _08Comparator比较器排序.练习;

import java.util.Comparator;
import java.util.TreeSet;

public class Test02 {
    public static void main(String[] args) {
        TreeSet<String> strings = new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                 int result =  o1.length()- o2.length();
                 if (result!=0){
                     //长度不一样按照长度排序
                     return result;
                 }else {
                     //如果长度一样，按照首字母排序
                     //int i = o1.charAt(0) - o2.charAt(0);
                     //return i;
                     return o1.compareTo(o2);
                 }

            }
        });


        strings.add("java");
        strings.add("python");
        strings.add("c++");

        System.out.println(strings);
    }
}
